function rm(c1, num) {
    var w = 120;
    var h = 30;
    c1.width = w;
    c1.height = h;

    var ctx = c1.getContext('2d');

    //填充背景颜色
    ctx.fillStyle = rc(180, 230);
    ctx.fillRect(0, 0, w, h);
    ctx.textBaseline = 'top';

    //绘制随机的字符
    for (var i = 0; i < num.length; i++) {
        var c = num[i];//下标随机取出
        var fs = rn(15, 35);//随机的字体大小
        var deg = rn(-45, 45);//随机的旋转角度
        ctx.font = fs + 'px SimHei';
        ctx.fillStyle = rc(80, 180);
        ctx.save();//存盘
        ctx.translate(30 * i + 15, 15);
        ctx.rotate(deg * Math.PI / 180);
        ctx.fillText(c, -15 + 5, -15);
        ctx.restore();//恢复存盘
    }

    //绘制6条干扰线
    for (var i = 0; i < 6; i++) {
        ctx.strokeStyle = rc(0, 255);
        ctx.beginPath();
        ctx.moveTo(rn(0, w), rn(0, h));
        ctx.lineTo(rn(0, w), rn(0, h));
        ctx.stroke();
    }

    //绘制50个杂色点-半径为0.5的圆形，填充
    for (var i = 0; i < 50; i++) {
        ctx.fillStyle = rc(0, 255);
        ctx.beginPath();
        ctx.arc(rn(0, w), rn(0, h), 0.5, 0, 2 * Math.PI);
        ctx.fill();
    }

    //random number：返回指定范围内的随机整数
    function rn(min, max) {
        var n = Math.floor(Math.random() * (max - min) + min);
        return n;
    }
    //random color：返回指定范围内的随机颜色
    //形如：rgb(x,x,x)
    function rc(min, max) {
        var r = rn(min, max);
        var g = rn(min, max);
        var b = rn(min, max);
        return `rgb(${r},${g},${b})`;
    }
}

const filetRoutes = (auth, routes) => {
    const router = routes.filter(item => {
        if (item.routes) {
            item.routes = filetRoutes(auth, item.routes)
        }
        return item.meta.includes(auth)
    }) 
    return router
}

export {
    rm,
    filetRoutes
}